package org.study.neo4j.boot.service;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.study.neo4j.boot.model.Course;
import org.study.neo4j.boot.repository.CourseRepository;

import java.util.List;

/**
 * 作用描述
 *
 * @author doveylovey
 * @version v1.0.0
 * @email 1135782208@qq.com
 * @date 2025年04月09日
 */
@Slf4j
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Service
public class CourseService {
    private final CourseRepository courseRepository;

    public Course saveCourse(Course course) {
        return courseRepository.save(course);
    }

    public List<Course> getAllCourses() {
        return courseRepository.findAll();
    }

    public Course getCourseByCode(String code) {
        return courseRepository.findByCode(code);
    }

    public List<Course> getCoursesByTeacherName(String teacherName) {
        return courseRepository.findByTeacherName(teacherName);
    }

    public List<Course> getCoursesByStudentName(String studentName) {
        return courseRepository.findByStudentName(studentName);
    }

    public void deleteCourse(String code) {
        courseRepository.deleteByCode(code);
    }
}
